package com.abc.cloud.service.impl;

import com.abc.cloud.dto.user.UserDto;
import com.abc.cloud.entity.UserEntity;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.abc.cloud.common.utils.PageUtil;
import com.abc.cloud.common.utils.Query;

import com.abc.cloud.dao.ChatUserDao;
import com.abc.cloud.entity.ChatUserEntity;
import com.abc.cloud.service.ChatUserService;


@Service("chatUserService")
public class ChatUserServiceImpl extends ServiceImpl<ChatUserDao, ChatUserEntity> implements ChatUserService {

    @Override
    public PageUtil queryPage(Map<String, Object> params) {
        IPage<ChatUserEntity> page = this.page(
                new Query<ChatUserEntity>().getPage(params),
                new QueryWrapper<ChatUserEntity>()
        );

        return new PageUtil(page);
    }

    @Override
    public List<UserDto> listByChatId(Long chatId) {
        return this.baseMapper.queryChatUserByChatId(chatId);
    }

    @Override
    public void increaseUnreadCount(Long chatId, Long userId) {
        this.baseMapper.increaseUnreadCount(chatId, userId);
    }

    @Override
    public void changeReadCount(Long chatId, Long userId, int readCount) {
        this.baseMapper.changeReadCount(chatId, userId, readCount);
    }

    @Override
    public void saveChatUser(Long id, Long userId) {
        ChatUserEntity chatUserEntity = new ChatUserEntity();
        chatUserEntity.setChatId(id);
        chatUserEntity.setUserId(userId);
        chatUserEntity.setUnreadCount(0);
        this.baseMapper.insert(chatUserEntity);
    }
}